<template>
  <router-view/>
</template>

<script>
import {getCurrentInstance, onMounted} from "vue";

export default {
  name: 'App',
  setup() {
    const {proxy} = getCurrentInstance()
    let token = localStorage.getItem("access_token");
    proxy.$service.accessToken({
      clientId: proxy.$concat.appKey,
      clientSecret: proxy.$concat.appSecret,
    }).then(result => {
      let newToken = result.res.data.accessToken;
      if (newToken !== token) {
        localStorage.setItem("access_token", result.res.data.accessToken);
        localStorage.setItem("refresh_token", result.res.data.refreshToken);
      }
    })
    let userToken = localStorage.getItem("user_token")
    if (userToken === null) {
      const nowRoute=proxy.$router.currentRoute.value.path
      console.log("nowpage is ",nowRoute)
      if (nowRoute !='/forgetPwd'){
        proxy.$router.push("/login")
      }
    } else {
      let userInfo = localStorage.getItem("user_info")
      if (userInfo.type === 'ADMIN')
        proxy.$router.push("/home")
      else
        proxy.$router.push("/userDetail")
    }
  }
}
</script>
